
 <!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  
    <title>前端入门3--HTML和CSS | Here. There.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3, minimum-scale=1">
    
    <meta name="author" content="被删">
    
    <meta name="description" content="《前端入门》系列主要为个人对前端一些经验和认识总结。本文稍微讲一下HTML和CSS。">
    
    
    
    
    <link rel="alternate" href="/atom.xml" title="Here. There." type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/pacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/pacman.jpg">
    
    <link rel="stylesheet" href="/css/style.css">
    
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?3d902de4a19cf2bf179534ffd2dd7b7f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>

  <body>
    <header>
      <div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/sun.png" alt="Here. There." title="Here. There."/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Here. There.">Here. There.</a></h1>
				<h2 class="blog-motto">Love ice cream. Love sunshine. Love life. Love the world. Love myself. Love you.</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="菜单">
			</a></div>
			<nav class="animated">
				<ul>
					
						<li><a href="/">首页</a></li>
					
						<li><a href="https://github.com/godbasin/godbasin.github.io">所有文章</a></li>
					
						<li><a href="/archives">归档</a></li>
					
						<li><a href="/categories">分类</a></li>
					
						<li><a href="/about">关于我</a></li>
					
				</ul>
			</nav>			
</div>

    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2018/04/21/front-end-3-html-css/" title="前端入门3--HTML和CSS" itemprop="url">前端入门3--HTML和CSS</a>
  </h1>
  <p class="article-author">By
    
      <a href="https://godbasin.github.io" title="被删">被删</a>
    </p>
  <p class="article-time">
    <time datetime="2018-04-21T09:25:32.000Z" itemprop="datePublished">2018-04-21</time>
    更新日期:<time datetime="2018-08-18T12:58:12.364Z" itemprop="dateModified">2018-08-18</time>
    
  </p>
</header>
	<div class="article-content">
		
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">文章目录</strong>
		<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#编辑器"><span class="toc-number">1.</span> <span class="toc-text">编辑器</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#IDE"><span class="toc-number">1.1.</span> <span class="toc-text">IDE</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文本编辑器"><span class="toc-number">1.2.</span> <span class="toc-text">文本编辑器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提升写码幸福指数"><span class="toc-number">1.3.</span> <span class="toc-text">提升写码幸福指数</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#HTML与CSS"><span class="toc-number">2.</span> <span class="toc-text">HTML与CSS</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#盒子模型"><span class="toc-number">2.1.</span> <span class="toc-text">盒子模型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#概念"><span class="toc-number">2.1.1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#margin-叠加"><span class="toc-number">2.1.2.</span> <span class="toc-text">margin 叠加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#盒模型计算"><span class="toc-number">2.1.3.</span> <span class="toc-text">盒模型计算</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#内联元素与块状元素"><span class="toc-number">2.2.</span> <span class="toc-text">内联元素与块状元素</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#内联元素"><span class="toc-number">2.2.1.</span> <span class="toc-text">内联元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#块状元素"><span class="toc-number">2.2.2.</span> <span class="toc-text">块状元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#常用的display属性"><span class="toc-number">2.2.3.</span> <span class="toc-text">常用的display属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#float浮动"><span class="toc-number">2.2.4.</span> <span class="toc-text">float浮动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#具体说明"><span class="toc-number">2.2.5.</span> <span class="toc-text">具体说明</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#元素定位"><span class="toc-number">2.3.</span> <span class="toc-text">元素定位</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#static"><span class="toc-number">2.3.1.</span> <span class="toc-text">static</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#inherit"><span class="toc-number">2.3.2.</span> <span class="toc-text">inherit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#relative"><span class="toc-number">2.3.3.</span> <span class="toc-text">relative</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#absolute"><span class="toc-number">2.3.4.</span> <span class="toc-text">absolute</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fixed"><span class="toc-number">2.3.5.</span> <span class="toc-text">fixed</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#元素堆叠"><span class="toc-number">2.4.</span> <span class="toc-text">元素堆叠</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#z-index"><span class="toc-number">2.4.1.</span> <span class="toc-text">z-index</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#具体说明-1"><span class="toc-number">2.4.2.</span> <span class="toc-text">具体说明</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
		</div>
		
		<p>《前端入门》系列主要为个人对前端一些经验和认识总结。本文稍微讲一下HTML和CSS。<br><a id="more"></a></p>
<h1 id="编辑器"><a href="#编辑器" class="headerlink" title="编辑器"></a>编辑器</h1><hr>
<p>写代码，怎么可以少了编辑器呢。</p>
<h2 id="IDE"><a href="#IDE" class="headerlink" title="IDE"></a>IDE</h2><p>集成开发环境（Integrated Development Environment，简称 IDE）是一种辅助程序开发人员开发软件的应用软件，在开发工具内部就可以辅助编写源代码文本、并编译打包成为可用的程序，有些甚至可以设计图形接口。</p>
<p>简单来说，IDE 会集成了很多工具、插件和环境，常见代码提示、错误提示、编译工具等等，在 IDE 下面打开一个 web 项目，很多的辅助信息都帮你解析好了。<br>而相对来说，IDE 比起文本编辑器就会笨重很多，尤其在多项目开发管理、编辑器启动的时候，速度明显下降。</p>
<p>前端常用的 IDE 无非是 Webstorm 了。</p>
<h2 id="文本编辑器"><a href="#文本编辑器" class="headerlink" title="文本编辑器"></a>文本编辑器</h2><p>文本编辑器最大的优势，便是轻。像项目多的时候，常常是打开多个文本编辑器，也不至于卡顿。</p>
<p>而文本编辑器通常也是很灵活的，可以安装需要的一些插件，也能获得想要的辅助功能。</p>
<p>前端常用的文本编辑器有 Subline、VSCode 等等。</p>
<h2 id="提升写码幸福指数"><a href="#提升写码幸福指数" class="headerlink" title="提升写码幸福指数"></a>提升写码幸福指数</h2><p>作为伴随长时间的同伴，当然要好好设置一下啦。</p>
<ol>
<li><p>选择喜欢的主题样式。<br>个人比较喜欢 VSCode 的默认样式，大家也可以去下载各种的主题或是自定义样式。</p>
</li>
<li><p>安装一些插件。<br>像本骚年前段时间安装的一个 VSCode 插件：</p>
</li>
</ol>
<p><img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20171108125834.jpg" alt="image"></p>
<p>还有比较出名的当然是 Atom 的 power mode 啦：</p>
<p><img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/68747470733a2f2f636c6f75642e67697468756275736572636f6e74656e742e636f6d2f6173736574732f3638383431352f31313631353536352f31306631363435362d396336352d313165352d386166342d3236356630316663383361302e676966.gif" alt="image"></p>
<p>嘛，喜欢的事情要做得开心才对啦。除了编辑器，一台好的电脑、机械键盘、耳机等都是写码必备的提高幸福指数的装备啦。</p>
<p>我认识的很多很(ai)牛(zhuang)逼(bi)的程序员，都会让写代码变成很开心的事情。而这样的态度，也是很棒的生活态度。</p>
<h1 id="HTML与CSS"><a href="#HTML与CSS" class="headerlink" title="HTML与CSS"></a>HTML与CSS</h1><hr>
<p>上一节也有简单说过 HTML 相关的，我想想这里讲些啥的好。<br>这里主要针对一些样式的逻辑来说明，其他详细的属性和设置值希望大家已经在 <a href="http://www.w3school.com.cn/" target="_blank" rel="external">w3c</a> 或是 <a href="https://developer.mozilla.org/zh-CN/docs/Web/CSS" target="_blank" rel="external">MDN</a> 上学习过了。</p>
<h2 id="盒子模型"><a href="#盒子模型" class="headerlink" title="盒子模型"></a>盒子模型</h2><p>我们能从控制台的 Element 模块里，找到这样的盒子模型：</p>
<p><img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/1510119051%281%29.png" alt="image"></p>
<p>盒模型(box model)是 CSS 中的一个重要概念，它是元素大小的呈现方式。</p>
<h3 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h3><p>在一个文档中，每个元素都被表示为一个矩形的盒子。确定这些盒子的尺寸, 属性（像它的颜色，背景，边框方面）和位置是渲染引擎的目标。</p>
<p>在 CSS 中，使用标准盒模型描述这些矩形盒子中的每一个。这个模型描述了元素所占空间的内容。<br>每个盒子有四个边：外边距边（<code>margin</code>）,边框边（<code>border</code>）,内填充边（<code>padding</code>）与内容边（<code>content</code>）。 </p>
<h3 id="margin-叠加"><a href="#margin-叠加" class="headerlink" title="margin 叠加"></a>margin 叠加</h3><p>当两个或更多个垂直边距相遇时，它们将形成一个外边距（<code>margin</code>）。</p>
<p><code>margin</code>的叠加会有一些混淆，需要注意的地方是：<br> 外边距（<code>margin</code>）的高度等于两个发生叠加的外边距的高度中的较大者。<br> <strong>只有普通文档流中块框的垂直外边距才会发生外边距叠加。行内框、 浮动框或绝对定位框之间的外边距不会叠加。</strong></p>
<h3 id="盒模型计算"><a href="#盒模型计算" class="headerlink" title="盒模型计算"></a>盒模型计算</h3><p>CSS3 中新增了一种盒模型计算方式：<code>box-sizing</code>属性。盒模型默认的值是<code>content-box</code>, 新增的值是<code>padding-box</code>和<code>border-box</code>，几种盒模型计算元素宽高的区别如下：</p>
<p><strong>content-box（默认）</strong><br>元素宽高(<code>width/height</code>)等于：<code>content</code><br>布局所占宽高等于：<code>width/height(content) + border + padding</code></p>
<p><strong>padding-box</strong><br>元素宽高(<code>width/height</code>)等于：<code>content + padding</code><br>布局所占宽高等于：<code>width/height(content + padding) + border</code></p>
<p><strong>border-box</strong><br>元素宽高(<code>width/height</code>)等于：<code>content + padding + border</code><br>布局所占宽高等于：<code>width/height(content + padding + border)</code></p>
<h2 id="内联元素与块状元素"><a href="#内联元素与块状元素" class="headerlink" title="内联元素与块状元素"></a>内联元素与块状元素</h2><h3 id="内联元素"><a href="#内联元素" class="headerlink" title="内联元素"></a>内联元素</h3><p>内联元素又称行内元素等，表示位于行内的元素。<br>内联元素只能容纳文本或者其他内联元素，它允许其他内联元素与其位于同一行。<br>内联元素的宽度高度不起作用。</p>
<p>常见的内联元素：<code>&lt;a&gt;</code>/<code>&lt;span&gt;</code>/<code>&lt;i&gt;</code>/<code>&lt;strong&gt;</code>等。</p>
<h3 id="块状元素"><a href="#块状元素" class="headerlink" title="块状元素"></a>块状元素</h3><p>块状元素一般是其他元素的容器，可容纳内联元素和其他块状元素。<br>块状元素排斥其他元素与其位于同一行。<br>块状元素的宽度高度起作用。</p>
<p>常见的块状元素有：</p>
<ul>
<li><code>&lt;div&gt;</code>/<code>&lt;p&gt;</code>/<code>&lt;h1&gt;</code>/<code>&lt;h2&gt;…&lt;h6&gt;</code>/<code>&lt;ul&gt;</code>/<code>&lt;ol&gt;</code></li>
<li>HTML5新元素: <code>&lt;section&gt;</code>/<code>&lt;article&gt;</code>/<code>&lt;header&gt;</code>/<code>&lt;footer&gt;</code>等</li>
</ul>
<h3 id="常用的display属性"><a href="#常用的display属性" class="headerlink" title="常用的display属性"></a>常用的display属性</h3><p><strong>block：块状元素</strong></p>
<ul>
<li>可容纳其他块状元素或内联元素</li>
<li>排斥其他元素与其位于同一行</li>
<li>宽度高度起作用，<code>block</code>元素可以设置宽度<code>width</code>和高度<code>height</code>，有效</li>
</ul>
<p><strong>inline：内联元素</strong></p>
<ul>
<li>位于行内，即位于块状元素或者其他内联元素内</li>
<li>只能容纳文本或者其他内联元素</li>
<li>允许其他内联元素与其位于同一行</li>
<li>inline元素的宽度高度不起作用</li>
</ul>
<p><strong>inline-block元素</strong></p>
<ul>
<li>与<code>inline</code>元素相似的地方<ul>
<li>位于行内，即位于块状元素或者其他内联元素内</li>
<li>允许其他内联元素与其位于同一行</li>
</ul>
</li>
<li><p>与<code>block</code>元素相似的地方</p>
<ul>
<li>可容纳其他块状元素或内联元素</li>
<li>宽度高度起作用</li>
</ul>
</li>
<li><p>使用<code>inline-block</code>可以很方便解决一些问题:</p>
<ul>
<li>使元素居中</li>
<li><code>inline</code>元素<code>a</code>/<code>span</code>设置宽高</li>
<li>将多个块状元素放在一行</li>
</ul>
</li>
</ul>
<h3 id="float浮动"><a href="#float浮动" class="headerlink" title="float浮动"></a>float浮动</h3><p><code>float</code>属性定义元素在哪个方向浮动。<br><code>float</code>属性可应用于图像，使文本围绕在图像周围。</p>
<p>使用<code>float</code>还可能遇到高度塌陷的问题，而可以使用几个方法解决：</p>
<ul>
<li>父元素使用<code>overflow: hidden</code>（此时高度为<code>auto</code>）</li>
<li>使父元素也成为浮动<code>float</code>元素</li>
<li>使用<code>clear</code>清除浮动</li>
</ul>
<p><code>float</code>撑开父元素主要依赖BFC原则。</p>
<p><strong>BFC 特性：</strong></p>
<ol>
<li>BFC 会阻止垂直外边距（margin-top、margin-bottom）折叠。</li>
<li>BFC 不会重叠浮动元素。</li>
<li>BFC 可以包含浮动。</li>
</ol>
<h3 id="具体说明"><a href="#具体说明" class="headerlink" title="具体说明"></a>具体说明</h3><p>以上的一些样式属性和方法，更多具体说明可参考<a href="https://godbasin.github.io/2016/06/26/about-display/">《CSS的display有关》</a>。</p>
<h2 id="元素定位"><a href="#元素定位" class="headerlink" title="元素定位"></a>元素定位</h2><p><strong>文档流</strong>：正常的文档流也叫普通流，在HTML里面的写法就是从上到下，从左到右的排版布局。</p>
<p>而我们常用的布局，与<code>position</code>样式属性紧紧相关。</p>
<h3 id="static"><a href="#static" class="headerlink" title="static"></a>static</h3><p>默认值。没有定位，元素出现在正常的流中（忽略 top, bottom, left, right 或者 z-index 声明）。</p>
<h3 id="inherit"><a href="#inherit" class="headerlink" title="inherit"></a>inherit</h3><p>规定应该从父元素继承 position 属性的值。</p>
<h3 id="relative"><a href="#relative" class="headerlink" title="relative"></a>relative</h3><p>生成相对定位的元素，相对于其正常位置进行定位。</p>
<p><code>relative</code>的特点：</p>
<ul>
<li>保持原有文档流，但相对本身的原始位置发生位移，且占空间</li>
<li>元素也遵循从上到下，从左到右的排版布局</li>
<li>相对于其正常位置进行定位，在这里设置了<code>relative</code>的元素相对其原本位置（<code>position: static</code>）进行位移</li>
<li>元素占有原本位置，因此下一个元素会排到该元素后方</li>
<li>元素占位不会随着定位的改变而改变。也就是说<code>relative</code>在文档流中占有的位置与其原本位置（<code>position: static</code>）相同</li>
</ul>
<p>这里有个需要注意的地方： 虽然<code>relative</code>元素占位与<code>static</code>相同，但会溢出父元素，撑开整个页面（<code>document</code>）。</p>
<h3 id="absolute"><a href="#absolute" class="headerlink" title="absolute"></a>absolute</h3><p>生成绝对定位的元素，相对于<code>static</code>定位以外的第一个父元素进行定位。<br>元素的位置通过<code>left</code>, <code>top</code>, <code>right</code>以及<code>bottom</code>属性进行规定。</p>
<p><code>absolute</code>的特点：</p>
<ul>
<li><code>absolute</code>元素脱离文档流</li>
<li><code>absolute</code>元素不占位，因此下一个符合普通流的元素会略过<code>absolute</code>元素排到其上一个元素的后方</li>
<li><code>absolute</code>元素的定位是相对于<code>static</code>定位以外的第一个父元素进行定位</li>
</ul>
<h3 id="fixed"><a href="#fixed" class="headerlink" title="fixed"></a>fixed</h3><p>生成绝对定位的元素，相对于浏览器窗口进行定位。<br>元素的位置通过<code>left</code>, <code>top</code>, <code>right</code>以及<code>bottom</code>属性进行规定。</p>
<p><code>fixed</code>的特点：</p>
<ul>
<li><code>fixed</code>元素脱离文档流</li>
<li><code>fixed</code>元素不占位</li>
<li><code>fixed</code>相对于浏览器窗口来定位，不管是否有<code>static</code>定位以外的父元素</li>
<li><code>absolute</code>元素会随着页面的滚动而滚动，而<code>fixed</code>不会</li>
</ul>
<h2 id="元素堆叠"><a href="#元素堆叠" class="headerlink" title="元素堆叠"></a>元素堆叠</h2><p>元素的堆叠方式和顺序，除了与<code>position</code>定位有关，也与<code>z-index</code>有关。</p>
<h3 id="z-index"><a href="#z-index" class="headerlink" title="z-index"></a>z-index</h3><p>有关<code>z-index</code>的说明：</p>
<ol>
<li>无<code>z-index</code>或者<code>z-index</code>值相等时，堆叠顺序均由元素在文档中的先后位置决定，后出现的会在上面。</li>
<li>当向上追溯找不到含有<code>z-index</code>值的父元素的情况下，则可以视为自由的<code>z-index</code>元素。</li>
<li>自由的<code>z-index</code>元素可以与其他自由的定位元素或者父元素的同级兄弟定位元素来比较<code>z-index</code>的值，决定其堆叠顺序。</li>
<li><code>z-index</code>值只决定同一父元素中的同级子元素的堆叠顺序。</li>
<li>父元素的<code>z-index</code>值为子元素定义了堆叠顺序，即子元素依赖于父元素<code>z-index</code>值来获得页面中的堆叠顺序。</li>
</ol>
<h3 id="具体说明-1"><a href="#具体说明-1" class="headerlink" title="具体说明"></a>具体说明</h3><p>有关元素定位和堆叠的更多说明，可以参考文章<a href="https://godbasin.github.io/2016/06/25/about-position/">《CSS的position和z-index有关》</a>。</p>
<h1 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h1><hr>
<p>本节简单介绍了关于 HTML 和 CSS 主要的一些规则和说明，或许有些杂乱，但这些都是我们在调试样式的时候需要遵循的逻辑。<br>即使是元素的尺寸和颜色，或许也是有一套规则的，只要掌握了这些原理，debug速度不就快很多了嘛。</p>
  
		
		<p style="margin-top:50px;">查看Github有更多内容噢：<a href="https://github.com/godbasin">https://github.com/godbasin</a></p>
	</div>
	<img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/2code2.jpg" width="200" height="200" style="display:block;margin: 0 auto;" />
	<p style="text-align: center;margin-top: 10px;margin-bottom: 20px;">码生艰难，写文不易，给我家猪囤点猫粮了喵~</p>
	<div class="author-right">
  		<p>作者：被删</p>
  		<p>出处：<a href="https://godbasin.github.io">https://godbasin.github.io</a></p>
  		<p>本文版权归作者所有，欢迎转载，但未经作者同意必须保留此段声明，且在文章页面明显位置给出原文连接，否则保留追究法律责任的权利。</p>
	</div>
		<footer class="article-footer clearfix">

  <div class="article-tags">
  
  <span></span> <a href="/tags/分享/">分享</a>
  </div>


<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/js什锦/">js什锦</a>
</div>



<div class="article-share" id="share">

  
<!-- JiaThis Button BEGIN -->
<div class="jiathis_style_24x24">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_weixin"></a>
	<a class="jiathis_button_renren"></a>
	<a href="http://www.jiathis.com/share?uid=2134021" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
</div>
<script type="text/javascript">
var jiathis_config = {data_track_clickback:'true'};
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=2134021" charset="utf-8"></script>
<!-- JiaThis Button END -->   


</div>
</footer>   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2018/04/29/front-end-4-dom-bom/" title="前端入门4--DOM和BOM">
  <strong>PREVIOUS:</strong><br/>
  <span>
  前端入门4--DOM和BOM</span>
</a>
</div>


<div class="next">
<a href="/2018/04/14/front-end-2-front-end-page/"  title="前端入门2--编写页面">
 <strong>NEXT:</strong><br/> 
 <span>前端入门2--编写页面
</span>
</a>
</div>

</nav>

	<!-- 如果不是首页且没使用 `comments: false` 关闭评论，则尝试加载评论 -->

    <!-- 配置中启用多说时，导入相应代码 -->
    


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="显示侧边栏"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">文章目录</strong>
  <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#编辑器"><span class="toc-number">1.</span> <span class="toc-text">编辑器</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#IDE"><span class="toc-number">1.1.</span> <span class="toc-text">IDE</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文本编辑器"><span class="toc-number">1.2.</span> <span class="toc-text">文本编辑器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提升写码幸福指数"><span class="toc-number">1.3.</span> <span class="toc-text">提升写码幸福指数</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#HTML与CSS"><span class="toc-number">2.</span> <span class="toc-text">HTML与CSS</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#盒子模型"><span class="toc-number">2.1.</span> <span class="toc-text">盒子模型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#概念"><span class="toc-number">2.1.1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#margin-叠加"><span class="toc-number">2.1.2.</span> <span class="toc-text">margin 叠加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#盒模型计算"><span class="toc-number">2.1.3.</span> <span class="toc-text">盒模型计算</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#内联元素与块状元素"><span class="toc-number">2.2.</span> <span class="toc-text">内联元素与块状元素</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#内联元素"><span class="toc-number">2.2.1.</span> <span class="toc-text">内联元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#块状元素"><span class="toc-number">2.2.2.</span> <span class="toc-text">块状元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#常用的display属性"><span class="toc-number">2.2.3.</span> <span class="toc-text">常用的display属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#float浮动"><span class="toc-number">2.2.4.</span> <span class="toc-text">float浮动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#具体说明"><span class="toc-number">2.2.5.</span> <span class="toc-text">具体说明</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#元素定位"><span class="toc-number">2.3.</span> <span class="toc-text">元素定位</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#static"><span class="toc-number">2.3.1.</span> <span class="toc-text">static</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#inherit"><span class="toc-number">2.3.2.</span> <span class="toc-text">inherit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#relative"><span class="toc-number">2.3.3.</span> <span class="toc-text">relative</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#absolute"><span class="toc-number">2.3.4.</span> <span class="toc-text">absolute</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fixed"><span class="toc-number">2.3.5.</span> <span class="toc-text">fixed</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#元素堆叠"><span class="toc-number">2.4.</span> <span class="toc-text">元素堆叠</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#z-index"><span class="toc-number">2.4.1.</span> <span class="toc-text">z-index</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#具体说明-1"><span class="toc-number">2.4.2.</span> <span class="toc-text">具体说明</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="隐藏侧边栏"></a></div>
<aside class="clearfix">

  	
	<div class="archiveslist">
		<p class="asidetitle">最近文章</p>
			<ul class="archive-list">
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/11/vue-for-everyone-2/" title="9102全员学Vue--2.怎么三两下拼出一个页面">9102全员学Vue--2.怎么三两...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/06/30/about-front-end-2-principle/" title="前端这几年--2.工作原则和选择">前端这几年--2.工作原则和选择...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/06/27/vue-for-everyone-1/" title="9102全员学Vue--1.如何理解前端和Vue">9102全员学Vue--1.如何理解...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/06/17/wxapp-latest-20190617/" title="小程序开发月刊第六期（20190617）">小程序开发月刊第六期（2019061...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/06/17/wxapp-generate/" title="小程序的诞生">小程序的诞生</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/05/15/wxapp-latest-20190515/" title="小程序开发月刊第五期（20190515）">小程序开发月刊第五期（2019051...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/04/15/wxapp-latest-20190415/" title="小程序开发月刊第四期（20190415）">小程序开发月刊第四期（2019041...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/04/13/about-front-end-1-begin-in/" title="前端这几年--1.转岗之路">前端这几年--1.转岗之路...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/03/15/wxapp-latest-20190315/" title="小程序开发月刊第三期（20190315）">小程序开发月刊第三期（2019031...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/03/10/work-2-article/" title="写文章这件事">写文章这件事</a>
				</li>
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
			</ul>
	</div>


  
  <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">归档</a></p>
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">五月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">四月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">三月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">一月 2019</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">十二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">十一月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">十月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">九月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/08/">八月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">七月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">六月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">五月 2018</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">15</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">二月 2017</a><span class="archive-list-count">41</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/">一月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/">十二月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/">十一月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/">十月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">九月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">七月 2016</a><span class="archive-list-count">14</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">9</span></li></ul>
  </div>


  
<div class="archiveslist">
	<p class="asidetitle"><a href="/categories">分类</a></p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/CSS炒饭/" title="CSS炒饭">CSS炒饭<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/D3小馒头/" title="D3小馒头">D3小馒头<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular2火锅/" title="angular2火锅">angular2火锅<sup>25</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular混搭/" title="angular混搭">angular混搭<sup>33</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/box2djs方糖/" title="box2djs方糖">box2djs方糖<sup>34</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/cyclejs哈根达斯/" title="cyclejs哈根达斯">cyclejs哈根达斯<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/jQuery杂烩/" title="jQuery杂烩">jQuery杂烩<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/js什锦/" title="js什锦">js什锦<sup>26</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/react沙拉/" title="react沙拉">react沙拉<sup>16</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/three-js奶茶/" title="three.js奶茶">three.js奶茶<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/vue八宝粥/" title="vue八宝粥">vue八宝粥<sup>28</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/webpack宾治/" title="webpack宾治">webpack宾治<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/web乱炖/" title="web乱炖">web乱炖<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/前端满汉全席/" title="前端满汉全席">前端满汉全席<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/喵/" title="喵">喵<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/小程序双皮奶/" title="小程序双皮奶">小程序双皮奶<sup>21</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/工作这杯茶/" title="工作这杯茶">工作这杯茶<sup>4</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/应用巧克力盒/" title="应用巧克力盒">应用巧克力盒<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/思想棉花糖/" title="思想棉花糖">思想棉花糖<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/柴米油盐工具集/" title="柴米油盐工具集">柴米油盐工具集<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/非前端钙片/" title="非前端钙片">非前端钙片<sup>7</sup></a>
			</li>
		
		</ul>
</div>


  
<div class="archiveslist">
	<p class="asidetitle">标签</p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/分享/" title="分享">分享<sup>44</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/原创部件/" title="原创部件">原创部件<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/心态/" title="心态">心态<sup>4</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/教程/" title="教程">教程<sup>65</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/晒猫/" title="晒猫">晒猫<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/笔记/" title="笔记">笔记<sup>121</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/算法/" title="算法">算法<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/自制插件/" title="自制插件">自制插件<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/逻辑实现/" title="逻辑实现">逻辑实现<sup>5</sup></a>
			</li>
		
		</ul>
</div>


    <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">about</a></p>
      <ul class="archive-list">
      	<li class="archive-list-item">
      		<a>wangbeishan@163.com</a>
      		<a href="https://github.com/godbasin">github.com/godbasin</a>
      	</li>
      </ul>
  </div>

  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS 订阅</a>
</div>

</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<section class="info">
		<p> 即使梦想再小，却很伟大 ^_^ </p>
	</section>
	 
		<p class="copyright">Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/A-limon/pacman" target="_blank" title="Pacman">Pacman</a> © 2019 
		
		<a href="https://godbasin.github.io" target="_blank" title="被删">被删</a>
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else
    {
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      h  = $('article h2')
      ah = $('article h2'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  if(ah.length==0){
    t.css('display','none');
  }else{
    c.click(function(){
      ta.css('display', 'block').addClass('fadeIn');
    });
    o.click(function(){
      ta.css('display', 'none');
    });
    $(window).scroll(function(){
      ta.css("top",Math.max(140,320-$(this).scrollTop()));
    });
  };
});
</script>







  </body>
</html>
